package us.icitap.cm.ui.custom;

import us.icitap.cm.ui.shared.GeneralVars;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Runo;



public class CustomFormLayout extends CustVerticalLayout{

	
	private final CustButton leftButton = new CustButton();
	private final CustButton rightButton = new CustButton();
	
	
	private final HorizontalLayout hl;
	
	public CustomFormLayout(String width, String caption){
		this(width, caption, "", "");
	}
	
	public CustomFormLayout(String width, String caption, String leftButtonCaption, String rightButtonCaption) {
		
		this.setCaption(caption);
		this.setWidth(width);
		hl = new HorizontalLayout();
		hl.setWidth("99%");
		hl.addStyleName("buttonsLayout");
		this.leftButton.setCaption(leftButtonCaption);
		this.rightButton.setCaption(rightButtonCaption);
		
		hl.addComponent(leftButton);
		hl.addComponent(rightButton);
		hl.setComponentAlignment(rightButton, Alignment.MIDDLE_RIGHT);
		leftButton.addStyleName(Runo.BUTTON_LINK);
		

	}

	@Override
	public void addComponent(Component c) {
		
		super.addComponent(c);
	}

	
	public void addFooter() {
		this.addComponent(hl);
	}
	
	
	public void addLeftClickListener(ClickListener clickListener){
		leftButton.addClickListener(clickListener);
	}
	
	public void addRightClickListener(ClickListener clickListener){
		rightButton.addClickListener(clickListener);
	}
	
	public void enableButtons(boolean enable){
		this.leftButton.setEnabled(enable);
		this.rightButton.setEnabled(enable);
	}
	
	public void displayLeftButton(boolean display){
		this.leftButton.setVisible(display);
	}
	
	public void setRightButtonOkIcon(){
		this.rightButton.setIcon(GeneralVars.CHECK_MARK_16_RES);
	}
	
	public void removeRightButtonIcon(){
		this.rightButton.setIcon(null);
	}
	
}
